package org.lex.net.uitl;

import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.util.Properties;

public class NetProperties {
	private static Properties props = new Properties();
	static {
		String path = System.getProperty("java.home");
		if (path == null)
			throw new Error("Can't find java.home ??");
		try {
			File file = new File(path, "lib");
			file = new File(file, "net.properties");
			path = file.getCanonicalPath();
			FileInputStream fis = new FileInputStream(path);
			BufferedInputStream bis = new BufferedInputStream(fis);
			props.load(bis);
			bis.close();
		} catch (Exception exception) {
		}
	}

	public static String get(String key) {
		try {
			return System.getProperty(key, props.getProperty(key));
		} catch (Exception e) {
		}
		return null;
	}

	public static Boolean getBoolean(String key) {
		try {
			String value = System.getProperty(key, props.getProperty(key));
			return Boolean.valueOf(value);
		} catch (Exception e) {
		}
		return null;
	}

	public static Integer getInteger(String key, int def) {
		String value = null;
		try {
			value = System.getProperty(key, props.getProperty(key));
		} catch (Exception e) {
		}
		if (value != null)
			try {
				return Integer.decode(value);
			} catch (NumberFormatException numberformatexception) {
			}
		return new Integer(def);
	}

	private NetProperties() {
	}
}
